package com.xiaoyun.util;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @Author: XiaoYun461
 * @Date: 2022/2/21 22:07
 */
@RestController
@RequestMapping("url")
public class InputUrlController {
    /**
     *  输入swagger json 地址 转为controller与pojo对象
     * @param url
     * @return
     */
    @GetMapping("/input")
    public List<String> inputUrl(@RequestParam String url) {
        Swagger2Ftl swagger2Ftl = new Swagger2Ftl();
        Set<String> setClassName = swagger2Ftl.processByUrl(url);
        return setClassName.stream().sorted().collect(Collectors.toList());
    }

    /**
     *  默认 转换 src/main/resources/sw.json -> controller与pojo对象
     * @return
     */
    @GetMapping("/default")
    public List<String> inputUrl() {
        Swagger2Ftl swagger2Ftl = new Swagger2Ftl();
        Set<String> setClassName = swagger2Ftl.processDefault();
        return setClassName.stream().sorted().collect(Collectors.toList());
    }
}
